<template>
  <div>
    <!-- 搜索 -->
    <!-- 索赔扣款信息查询 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="120" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :is-select-column="false"
      columnsRef="ClaimDebitsInfoQuerylgr"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary"  @click="exportFileBtn()">导出</multiuse-button>
      </template>
    </FilterTable>
    <Drawer :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <xiangqing @close="close" @save="save" :rowData="rowData"></xiangqing>
    </Drawer>
  </div>
</template>
<script>
import xiangqing from './xiangqing.vue';
import { exportExcelFile } from '@/utils/index';
import { getListByPage,getListForExport } from '@/api/claim/dealer/ClaimDebitsInfoQuery';
import { dictionary } from '@/utils/dictMixin';
export default {
   mixins: [dictionary],
  components: {
    xiangqing
  },
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      rowData: {},
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: { techStatusStrs: '55021002',xhrAbort: true}, //ipa 接口
      fetchapi: getListByPage,
      selectedRows: [], //选中经销商
      dialogTitle: '索赔扣款',
      visibleAdd: false
    };
  },
  created() {
    this.chuqi();
  },
  methods: {
    async chuqi() {
      // const res = await getPartType({ type: 5591 });
      // if (res.resultCode == 200) {
      //   delete  res.data[2]
      //   this.topFilterInit.find(x => x.fieldName == 'cbStatus').initialValue = '';
      //   this.topFilterInit.find(x => x.fieldName == 'cbStatus').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
      // }
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '索赔单号', fieldName: 'claimNo', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '扣款单号', fieldName: 'cbNo', placeholder: '请输入', initialValue: '' },
        { type: 'SELECT', label: '扣款单状态', fieldName: 'cbStatus', placeholder: '请选择', initialValue: '', itemList: this.createDictList('5502',[55021001,55021003,55021004,55021005]) },
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val, {xhrAbort: false});
      // this.SELECT();
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          fixed: 'left',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.chooseOrderNo(props.row)}>
                  查看
                </multiuse-button>
              </div>
            );
          }
        },
        { title: '扣款单状态', dataIndex: 'statusStr', sorter: true },
        { title: '扣款单号', dataIndex: 'cbNo', sorter: true },
        // { title: '主损件代码', dataIndex: 'partCode', sorter: true },
        // { title: '主损件名称', dataIndex: 'partName', sorter: true },
        { title: '索赔单号', dataIndex: 'claimNo', sorter: true },
        // { title: '现结算金额', dataIndex: 'finalSumAmount', sorter: true },
        { title: '扣款金额', dataIndex: 'cbSumAmount', sorter: true },
        { title: '原审核金额', dataIndex: 'claimSumAmount', sorter: true },
        // { title: '申请金额', dataIndex: 'sumAmount', sorter: true },
        { title: '索赔类型', dataIndex: 'claimTypeStr', sorter: true },
        { title: '扣款原因', dataIndex: 'cbReason', sorter: true },
        { title: '备注', dataIndex: 'remarks', sorter: true },
        { title: '创建人', dataIndex: 'createdBy', sorter: true },
        { title: '创建日期', dataIndex: 'createdAt', sorter: true },
        { title: '确认人', dataIndex: 'confirmedBy', sorter: true },
        { title: '确认时间', dataIndex: 'confirmedAt', sorter: true },
        // { title: '确认时间', dataIndex: 'cbId', hidden: true }

      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    close() {
      this.visible = false;
    },
    chooseOrderNo(val) {
      this.rowData = val;
      this.visible = true;
    },
    save(obj) {
      this.topFilterInit.find(x => x.fieldName == 'model').initialValue = obj[0].address;
      this.visible = false;
    },
    // 导出
   async exportFileBtn() {
      // let json = Object.assign({}, { CODE: 'CODE_00000204' }, this.fetchParams);
      // let res = await exporturl(json);
      // if (res.resultCode == 200) {
      //   this.$router.push('/admin/auth/oem/downloadCenter');
      // }
      getListForExport(Object.assign({cbStatus:this.topFilterInit.find(x => x.fieldName == 'cbStatus').initialValue}, this.fetchParams)).then(res => {
        exportExcelFile(res.data, '索赔扣款信息导出');
      });
    },
    add() {
      this.visibleAdd = true;
    },
    closeAdd() {
      this.visibleAdd = false;
      this.fetchParams = { ...this.fetchParams };
    },
    saveAdd() {
      this.visibleAdd = false;
      this.fetchParams = { ...this.fetchParams };
    }
  }
  // mounted() {
  //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
  // }
};
</script>

<style lang="less" scoped></style>
